|
www.mxdraw.com
|
得到当前空间的所有实体
[helpstring("method AllSelect")]
HRESULT AllSelect([in,defaultvalue(NULL)] IMxDrawResbuf* filterData);|
参数 |
说明 |
|
[in,defaultvalue(NULL)] IMxDrawResbuf* filterData |
过滤条件 |
例如: Delphi 得到图上所有PL线,然后再PL线打碎,变成直线,和圆弧,得样条线,并离散成点.
procedure TForm3.Button1Click(Sender: TObject);
var ss : IMxDrawSelectionSet;
filter : IMxDrawResbuf;
ii,jj : Integer;
pEnt,pTmp : IMxDrawEntity;
pPolyline : IMxDrawPolyline;
param : IMxDrawResbuf;
line : IMxDrawLine;
pts,pte,minPt,maxPt,pt : IMxDrawPoint;
arc : IMxDrawArc;
spl : IMxDrawSpline;
points : IMxDrawPoints;
dApproxEps : DOUBLE;
blkRef : MxDrawBlockReference;
begin
// 创建一个选择集对象
ss := CoMxDrawSelectionSet.Create();
// 创建一个过滤条件对象
filter := CoMxDrawResbuf.Create();
// 选择图上所有实体
ss.AllSelect(filter);
// 遍历构造后的选择集实体,找到边界线。
for ii := 0 to ss.Count -1 do
begin
// 遍历所有实体
pEnt := ss.Item(ii);
// 对图块的处理.
pEnt.QueryInterface(MxDrawBlockReference, blkRef);
if blkRef <> nil then
begin
// 是个图块文件.
param := blkRef.Explode();
for jj := 0 to param.Count -1 do
begin
pTmp := IMxDrawEntity(param.AtObject(jj) );
pTmp.QueryInterface(IMxDrawLine, line);
if(line <> nil) then
begin
// 这是图块内的直线。
showmessage('Line');
end;
// 处理其它实体,图块里面还可能再嵌套图块,这时需要递归处理.
// ...
// 删除临时生成的文件.
pTmp.Erase();
end;
end;
///
pEnt.QueryInterface(IMxDrawSpline, spl);
if spl <> nil then
begin
// 对象是个样条线。
// 得到样条线的外包
points := spl.GetBoundingBox2();
// dApproxEps样条线的离形精度
dApproxEps := 0.01;
// 根据样条线的大小,动态确定离线精度。
if points.Count > 1 then
begin
// 外包的最小点,和最大点
minPt := points.Item(0);
maxPt := points.Item(1);
// dApproxEps取外包最短边长的 1/20
if abs(minPt.x - maxPt.x) < abs(minPt.y - maxPt.y)then
begin
dApproxEps := abs(minPt.x - maxPt.x) / 20;
end
else
begin
dApproxEps := abs(minPt.y - maxPt.y) / 20;
end;
// 如果为 dApproxEps零,就默认取 0.01
if dApproxEps < 0.0000001 then
dApproxEps := 0.01;
end;
// showmessage(Format('dApproxEps:%g',[dApproxEps]) );
// 离散样条线.
points := spl.GetSamplePoints(dApproxEps);
// 遍历样条线上的所有点,可以把这些点,做为样条线的拟合点,用来重生样条线。
for jj := 1 to points.Count -1 do
begin
pt := points.Item(jj);
showmessage(Format('X:%g,Y:%g',[pt.x,pt.y]) );
end;
end;
pEnt.QueryInterface(IMxDrawPolyline, pPolyline);
if pPolyline <> nil then
begin
// 得到一个PL线对象。
// 打碎PL线,把PL线变成直线,和圆弧
param := CoMxDrawResbuf.Create();
param.AddObjectId(pEnt.ObjectID);
// 调用打碎函数,打碎实体.
param := MxDrawResbuf(MxDrawX1.CallEx('Mx_Explode', param));
// 遍历打碎后的实体,得到所有曲线。
for jj := 1 to param.Count -1 do
begin
//
pEnt := IMxDrawEntity(param.AtObject(jj));
pEnt.QueryInterface(IMxDrawLine, line);
if(line <> nil) then
begin
// 这是PL线里的直线
// 得到直线的,开始点,和结束点,
pts := line.StartPoint;
pte := line.EndPoint;
//showmessage('line');
// 调用Delphi的绘制直线函数,绘直线
// ...
end;
pEnt.QueryInterface(IMxDrawArc, arc);
if(arc <> nil) then
begin
// 这是PL线里的圆弧
// 得到圆弧中点,半径,开始角,结束角,
// arc.Center;
// arc.StartAngle;
// arc.EndAngle;
// arc.Radius;
//showmessage('arc');
// 调用Delphi的绘圆弧函数,绘直线
// ...
end;
pEnt.Erase();
end;
end;
end;
end;
例如: Qt使用
QAxObject *filter = ui.axWidget->querySubObject("NewResbuf");
QAxObject *pss = ui.axWidget->querySubObject("NewSelectionSet");
pss->dynamicCall("AllSelect(QVariant)",filter->asVariant());
int iEntConut = pss->property("Count").toInt();
for(int i = 0; i < iEntConut;i++)
{
QAxObject* ent = pss->querySubObject("Item(const qint64&)",i);
qDebug() << ent->property("ObjectName");
}
例如: C#使用